﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;

namespace CosAging
{
    internal class JHCLIB
    {
        public struct PARAMETER
        {
            public float MarkSpeed;//标刻速度
            public float WorkSize; //标刻范围
            public float RedSpeed; //红光速度
            public float JumpSpeed;//跳转速度
            public float JumpLocationDelay; //跳转位置延时
            public float JumpDistanceDelay; //跳转距离延时
            public float OpenDelay;  //开光延时
            public float CloseDelay; //关光延时
            public float FoldDelay;  //拐点延时
            public float FinishDelay; //结束延时
            public PARAMETER(uint cmd)
            {
                this.MarkSpeed = 500.0f;
                this.WorkSize = 110.0f;
                this.RedSpeed = 3000.0f;
                this.JumpSpeed = 4000.0f;
                this.JumpLocationDelay = 0.0f;
                this.JumpDistanceDelay = 0.0f;
                this.OpenDelay = 0.0f;
                this.CloseDelay = 0.0f;
                this.FoldDelay = 0.0f;
                this.FinishDelay = 0.0f;
            }
        }
        public struct GALVOPARAM
        {
            public bool bXYExchange; //XY轴互换
            public bool bXAxisN;   //X轴负向
            public bool bYAxisN;   //Y轴负向
            private GALVOPARAM(uint cmd)
            {
                this.bXYExchange = false;
                this.bXAxisN = false;
                this.bYAxisN = false;
            }
        }
        public enum GalvanometerLocation
        {
            NotMove=0,
            GalvanometerCenter,
            SpecifiedLocation,
        }
        [StructLayout(LayoutKind.Sequential)]
        public struct JHCStatusdef
        {
            public byte InStatus; //IO 输入状态
            public byte InStatus2;
            public byte OutStatus;//IO 输出状态	
            public int freeSpace;//板卡剩余空间
            public ushort MotorStatus; // 辅助轴状态
            public byte MarkStatus; //运行状态
            public byte LaserStatus; //激光器状态
            public byte FootStatus;//脚踏状态	
            public int BeltSpeed;// 传送带速度
            public int MarkTimes; // 标刻次数
            //public byte MotorStatus;
            //public byte InState;
            //public byte RunStatus;
            //public byte LaserState;
            private JHCStatusdef(uint cmd)
            {
                this.InStatus = 0;
                this.InStatus2 = 0;
                this.OutStatus = 0;
                this.freeSpace = 0;
                this.MotorStatus = 0;
                this.MarkStatus = 0;
                this.LaserStatus = 0;
                this.FootStatus = 0;
                this.BeltSpeed = 0;
                this.MarkTimes = 0;
            }
        };
        [DllImport("JHCLIB.dll", CharSet = CharSet.Auto)]
        public static extern bool JHCOpenDevice(); //打开USB连接  USB全局
        [DllImport("JHCLIB.dll", CharSet = CharSet.Auto)]
        public static extern void JHCCloseDevice();//关闭USB连接
        [DllImport("JHCLIB.dll", CharSet = CharSet.Auto)]
        public static extern bool JHCIsOpen();     //USB是否打开       
        [DllImport("JHCLIB.dll", CharSet = CharSet.Auto)]
        public static extern void JHCSChSetPWM(uint Freq, byte Duty, bool Reverse);//设置激光器PWM
        [DllImport("JHCLIB.dll", CharSet = CharSet.Auto)]
        public static extern void JHCSchOutLine(float x1, float y1, float x2, float y2);//直线插点，起始点和结束点坐标 0.01mm
        [DllImport("JHCLIB.dll", CharSet = CharSet.Auto)]
        public static extern void JHCBufStart();//初始化数据的初始位置        
        [DllImport("JHCLIB.dll", CharSet = CharSet.Auto)]
        public static extern void JHCCorrectionSet(float To_Jz_X, float To_Jz_Y, float Px_Jz_X, float Px_Jz_Y,
                                    float Tx_Jz_X, float Tx_Jz_Y, float Scal_X, float Scal_Y);//设置校正的参数
        [DllImport("JHCLIB.dll", CharSet = CharSet.Auto)]
        public static extern void JHCSchLaserOut(float power, int type, int mode);//激光输出设置
        [DllImport("JHCLIB.dll", CharSet = CharSet.Auto)]
        public static extern void JHCSchOutRect(float x1, float y1, float x2, float y2);//矩形插点，对角点的坐标 0.01mm
        [DllImport("JHCLIB.dll", CharSet = CharSet.Auto)]
        public static extern void JHCSchOutCircle(float x, float y, float r);//圆形插点，圆心坐标以及半径 0.01mm
        [DllImport("JHCLIB.dll", CharSet = CharSet.Auto)]
        public static extern void JHCSchOutArc(float x, float y, float r, float starAngle, float endAngle);//圆弧插点，圆心坐标、半径、起始角度以及结束角度
        [DllImport("JHCLIB.dll", CharSet = CharSet.Auto)]
        public static extern void JHCSchOutEllipse(float x, float y, float rx, float ry);//椭圆形插点，椭圆心坐标以及X、Y半径 0.01mm
        [DllImport("JHCLIB.dll", CharSet = CharSet.Auto)]
        public static extern void JHCSchOutEArc(float x, float y, float rx, float ry, float starAngle, float endAngle);//椭圆弧插点，椭圆心坐标、半径X，Y、起始角度以及结束角度
        [DllImport("JHCLIB.dll", CharSet = CharSet.Auto)]
        public static extern void JHCCancel();//取消打标
        [DllImport("JHCLIB.dll", CharSet = CharSet.Auto)]
        public static extern void JHCPause();//暂停打标
        [DllImport("JHCLIB.dll", CharSet = CharSet.Auto)]
        public static extern void JHCResume();//恢复打标        
        [DllImport("JHCLIB.dll", CharSet = CharSet.Auto)]
        public static extern void JHCParameterSet(PARAMETER param);//参数设置
        [DllImport("JHCLIB.dll", CharSet = CharSet.Auto)]
        public static extern void JHCGalvoParameterSet(GALVOPARAM param);//振镜参数设置       
        [DllImport("JHCLIB.dll", CharSet = CharSet.Auto)]
        public static extern void JHCStartMarking();    //开始标刻（同时调用JHCWriteBuf和JHCBufEnd，作了线程的处理）
        [DllImport("JHCLIB.dll", CharSet = CharSet.Auto)]
        public static extern int JHCGetMarkingState();//获取打标状态       
        [DllImport("JHCLIB.dll", CharSet = CharSet.Auto)]
        public static extern int JHCGetSystemState(ref JHCStatusdef pStatusdef,bool bfootFlag);
        [DllImport("JHCLIB.dll", CharSet = CharSet.Auto)]
        public static extern int JHCIoOut(byte data1,byte data2,ushort data3);//IO输出
        [DllImport("JHCLIB.dll", CharSet = CharSet.Auto)]
        public static extern int JHCMotorOut(byte Id, float maxSpeed, float minSpeed, float acSpeed, byte motorType, float distance, float resolution);//辅助轴输出       
        [DllImport("JHCLIB.dll", CharSet = CharSet.Auto)]
        public static extern void JHCSchOutPoint(float x,float y, float t);//输出点 ，x,y为点的坐标，t为打点的时间，单位ms
        [DllImport("JHCLIB.dll", CharSet = CharSet.Auto)]
        public static extern void JHCSetPulseWidth(int npulseWidth);//设置脉冲宽度
    }
}
